<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>二手市场的表单</title>
<%@ include file="../../common_header.jsp"%>
<script type="text/javascript">
	//所有的子窗体都需要有一个save函数，当点击弹出窗体的保存按钮时所进行的操作
	function btnSave_click() {
			var fun_ret;
			var file = $('#uploadFile')[0];
			var imagSize =  document.getElementById("uploadFile").files[0];
			if(imagSize != null && imagSize != "" && !isNull( imagSize )){
				imagSize = imagSize.size;
			}
			name = file.value;
			var pic = /.+(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)$/;
			var end = name.substr(name.lastIndexOf("."));
			if (name != "" && name != null && end !=".jpg" && end !=".JPEG" && end !=".jpeg" &&end !=".JPG" && end !=".PNG" && end !=".png" ) {
				$.messager.alert("提示", " 您选择的不是图片文件，请重新选择！");
				return false;
			}else{
				if(imagSize > 204800){
						$.messager.alert("错误提示", "图片需要限制在200kb以内！");
				        return false;
				}
			}
			var formData = new FormData($('#formModule')[0]);
			$.ajax(
					{
						url : '${saveUrl}', //server script to process data
						type : 'POST',
						data : formData,
						async: false,
						cache : false,
						contentType : false,
						processData : false,
						dataType:'json',//请求的数据类型
						xhr : function() { // custom xhr
							myXhr = $.ajaxSettings.xhr();
							if (myXhr.upload) { // if upload property exists
								myXhr.upload.addEventListener('progress',
										progressHandlingFunction, false); // progressbar
							}
							return myXhr;
						},
						success : function(data) {
				               if(data.success == 0 )
				               {
				            	   fun_ret = true;
				                  
				               }
				               else
				               {
				            	   top.Ext.Msg.alert("返回提示",data.msg);
				               }
				           },
						error : errorHandler = function(data) {
							$.messager.alert("错误提示", data.msg);
							return false;
						}
					});	
	return fun_ret;
	}
	function progressHandlingFunction(e) {
		if (e.lengthComputable) {
			$('progress').attr({
				value : e.loaded,
				max : e.total
			});
		}
	}
	 $(document).ready(function(){
		//获取当前用户可查看到的部门
		showDataInCombotree('${ctx }/manage/sysDepartment/getAllDepaetment?flag=2',$("#depId"),'${model.sysDepartment.depId}');
	 });
</script>
</head>
<body>
	<div style="padding: 1px" align="center">
		<form id="formModule" method="post">
			<input id="marketId" type="hidden" name="marketId" value="${model.marketId }">
            <input id="photo" type="hidden" name="icon" value="${model.photo }">
			<table border="0">
				<tr height="30">
					<td>所属单位：</td>
                    <td><select id="depId" name="sysDepartment.depId" class="easyui-combotree" style="width:180px;height:25px" data-options="required:true,editable:false"></select>
                    </td>
					
				</tr>
				<!-- <tr height="30">
					<td>买(卖)家：</td>
                    <td><select id="custId" name="sysCustomer.custId" class="easyui-combotree" style="width:180px;height:25px" data-options="required:true,editable:false"></select>
                    </td>
				</tr> -->
				<tr height="30">
						<td>标题：</td>
						<td><input id="TITLE" maxlength="10" placeholder="请输入商品信息标题"
							class="easyui-validatebox textbox" type="text"
							name="title" data-options="required:true"
							style="width: 180px;height: 25px" value="${model.title }"></input></td>
					</tr>
				</tr>
				<tr height="50">
					<td>商品描述：</td>
					<td><textarea id="summary" maxlength="200" 
						class="easyui-validatebox textbox" 
						name="summary" data-options="required:true"
						style="width:180px;height:70px" >${model.summary }</textarea></td>
				</tr>
				<tr height="30">
					<td>联系号码：</td>
					<td><input id="LOGINNAME" maxlength="11" placeholder="请输入手机号"
						class="easyui-validatebox textbox" type="text" 
						name="phone" onkeyup="value=value.replace(/[^1234567890-]+/g,'')" validType="phone"
						style="width: 180px;height: 25px;text-align:center" value="${model.phone }"></input></td>
				</tr>
				<tr height="30">
					<td>价格：</td>
					<td><input id="price" maxlength="10" 
						class="easyui-validatebox textbox" type="text" onkeyup="value=value.replace(/[^1234567890.]+/g,'')"
						name="price" data-options="required:true"
						style="width: 180px;height: 25px" value="${model.price }"></input></td>
				</tr>
				<tr height="30">
					<td>商品类型：</td>
					<td><select id="flag" name="flag">
							<option value="1" <c:if test="${model.flag==1 }">selected</c:if>>买商品</option>
							<option value="2" <c:if test="${model.flag==2 }">selected</c:if>>卖商品</option>
					</select></td>
				</tr>
				<tr height="30">
					<td>状态：</td>
					<td><select id="status" name="status">
							<option value="9" <c:if test="${model.status==9 }">selected</c:if>>正常</option>
							<option value="1" <c:if test="${model.status==1 }">selected</c:if>>注销</option>
					</select></td>
				</tr>
					 <tr>
                    <td height="30">图片：</td>
                    <td><input type="file" class="easyui-linkbutton"
						data-options="toggle:true,group:'g2',plain:true"
						accept="image/*" id="uploadFile"
						name="uploadFile" style="width: 200px;" /></td>
                </tr>
			</table>
		</form>
	</div>
</body>
</html>
